<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="">
    <input type="text" name="username" placeholder="请输入用户名" id="username">
    <span id="usernameSpan"></span>
    <br>
    <input type="password" name="password" placeholder="请输入密码"> <br>
    <button>提交</button>
</form>
<!--  导入axios类库  -->
<script type="text/javascript" src="js/axios-0.18.0.js"></script>
<script type="text/javascript">
    document.getElementById("username").onblur=function(){
        let usernameValue=this.value;
        if(usernameValue.trim()){
            axios.post("http://localhost:8080/registerServlet","username="+usernameValue)
                .then(resp=>{
                    if(resp.data){
                        document.getElementById("usernameSpan").innerHTML="该用户名不存在";
                    }else{
                        document.getElementById("usernameSpan").innerHTML="该用户名已存在";
                    }
                });
        }
    }
</script>

</body>

</html>